package com.aliyun.messagemgt.web.controller;

import com.aliyun.messagemgt.application.service.MessageRecordService;
import com.aliyun.messagemgt.dto.query.MsgHandleLogQuery;
import com.aliyun.messagemgt.dto.query.MsgPushResultsQuery;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author: Xiaohang Lv
 * @Date: 2019/5/8 09:55
 */
@Api(tags = "对外部相关接口")
@RestController
@Validated
public class OuterController {

    @Autowired
    MessageRecordService messageRecordService;

    /**
     * 消息对外查询接口--包括已读未读
     * @param msgPushResultsQuery
     * @param bindingResult
     * @return
     */
    @RequestMapping("/outer/listMsgPushResults")
    public Object listMsgPushResults(@Valid @RequestBody MsgPushResultsQuery msgPushResultsQuery, BindingResult bindingResult){
        return messageRecordService.listMsgPushResults(msgPushResultsQuery);
    }

    /**
     * 对外更新==消息已读未读更新
     * @param msgHandleLogQuery
     * @param bindingResult
     * @return
     */
    @RequestMapping("/outer/updateStateRead")
    public Object updateStateRead(@Valid @RequestBody MsgHandleLogQuery msgHandleLogQuery, BindingResult bindingResult){
        if(msgHandleLogQuery.getReadStates() == null || msgHandleLogQuery.getReadStates()>1){
            msgHandleLogQuery.setReadStates(0);
        }
        return messageRecordService.updateMsgHandleLogStateRead(msgHandleLogQuery);
    }
}
